#include"Window.h"


LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
	Window* window = static_cast<Window*> (GetPropA(hWnd, "Owner"));
	if (!window) return DefWindowProcA(hWnd, msg, wParam, lParam);

	return DefWindowProcA(hWnd, msg, wParam, lParam);
}

//create and update window
Window::Window(int w, int h, const char* name):width(w),height(h)
{
	WNDCLASS wndClass = { CS_BYTEALIGNCLIENT,(WNDPROC)MsgProc,0,0,0,NULL,NULL, NULL, NULL, TEXT("Test") };
	if (!RegisterClass(&wndClass)) return;

	window = CreateWindow(TEXT("Test"), TEXT("Test"), WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, 0, 0, 0, 0, NULL, NULL, wndClass.hInstance, NULL);

	if (!window) return;

	hdc = GetDC(window);
	screenHdc = CreateCompatibleDC(hdc);

	BITMAPINFO bitmapInfo = { {sizeof(BITMAPINFOHEADER),width,height,1,32,BI_RGB,width * height * 4,0,0,0,0} };
	LPVOID ptr;

	HBITMAP bitmapHandler = CreateDIBSection(screenHdc, &bitmapInfo, DIB_RGB_COLORS, &ptr, 0, 0);
	if (!bitmapHandler) return;

	HBITMAP screenObj = (HBITMAP)SelectObject(screenHdc, bitmapHandler);

	SetWindowPos(window, NULL, 50, 50, width, height, (SWP_NOCOPYBITS | SWP_NOZORDER | SWP_SHOWWINDOW));

	ShowWindow(window, SW_NORMAL);
	UpdateWindow(window);

	
}

Window::~Window()
{
}



